#include <iostream>
#include <memory>
using namespace std;

class A{
public:
    A(int num = 0):_num(new int(num)){
        cout << "A()" << endl;
    }
    ~A(){
        cout << "~A()" << endl;
    }
    int* _num;
};

class myautoptr{
public:
    myautoptr(A* a):_ptr(a){
        //cout << "myautoptr(A* a)" << endl;
    }
    ~myautoptr(){
        //cout << "~myautoptr()" << endl;
        delete _ptr;
    }
    A* operator->(){
        return _ptr;
    }
    A& operator*(){
        return *_ptr;
    }
    A* _ptr;
};

int main()
{
    A* p = new A(10);
    myautoptr op(p);

    cout << *op->_num<< endl;
    return 0;
}
